package com.example.IoCpractice.Controller;

import com.example.IoCpractice.configuration.StudentConfiguration;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-13
 * Time: 16:11
 */
@RestController
@RequestMapping("/properties")
public class PropertiesController {
    @Value("${my.key}")
    private String myKey;

    @Value("${my.key1}")
    private Integer myKey1;

    @Value("${my.key2}")
    private Boolean myKey2;

    @RequestMapping("/readValue1")
    public String readValue1() {
        return "从配置信息中读取: " + myKey;
    }

    @PostConstruct
    public void readValue2() {
        System.out.println(("从配置信息中读取: " + myKey));
        System.out.println(("从配置信息中读取: " + myKey1));
        System.out.println(("从配置信息中读取: " + myKey2));
    }

    @Autowired
    private StudentConfiguration studentConfiguration;

    @RequestMapping("/readObject")
    public String readObject() {
        return studentConfiguration.toString();
    }

}
